using System;
using System.Collections.Generic;
using System.Text;
using ITAP.Core.Modelling;

namespace ITAP.Core.Calculations
{
    public class SimpleEqualProvider
    {
        #region IEqualProvider Members

        public static bool IsEqual(ITAP.Core.Modelling.ModelPoint first, ITAP.Core.Modelling.ModelPoint second, double tolerance)
        {
            if (ModelCalculations.GetDistance(first, second) < tolerance)
                return true;
            else
                return false;
            //if (SimpleEqualProvider.IsEqual(first.X, second.X, tolerance) && SimpleEqualProvider.IsEqual(first.Y, second.Y, tolerance))
            //    return true;
            //return false;
        }

        public static bool IsEqual(double first, double second, double tolerance)
        {
             if (double.IsInfinity(first) && double.IsInfinity(second) ||
                double.IsNaN(first) && double.IsNaN(second))        
                    return true;

            
            if (Math.Abs(second - first) < tolerance)
                return true;
            else
                return false;
        }

        #endregion

        public static bool IsEqual(Angle angle1, Angle angle2, double tolerance)
        {
            Angle a = angle1 - angle2;
            Angle b = angle2 - angle1;
            if (b > a)
                b = a;

            if (Math.Abs((b).Value) <= tolerance)
                return true;
            else
                return false;

        }
    }
}
